// src/main/java/mr/ali/webvideo/config/WeChatPayConfig.java
package mr.ali.webvideo.config;

import com.github.wxpay.sdk.WXPay;
import com.github.wxpay.sdk.WXPayConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.InputStream;

@Configuration
public class WeChatPayConfig {

    @Value("${wechat.appid}")
    private String appId;

    @Value("${wechat.mchId}")
    private String mchId;

    @Value("${wechat.key}")
    private String key;

    @Bean
    public WXPay wxPay() {
        WXPayConfig config = new WXPayConfig() {
            @Override
            public String getAppID() {
                return appId;
            }

            @Override
            public String getMchID() {
                return mchId;
            }

            @Override
            public String getKey() {
                return key;
            }

            @Override
            public InputStream getCertStream() {
                return null;
            }

            public String getCertPath() {
                // 如需使用退款等功能，需要证书路径
                return "";
            }

            @Override
            public int getHttpConnectTimeoutMs() {
                return 8000;
            }

            @Override
            public int getHttpReadTimeoutMs() {
                return 10000;
            }
        };
        return new WXPay(config);
    }

    // 添加获取商户ID的方法
    @Bean
    public String mchId() {
        return mchId;
    }
}
